package com.qys.livesMall.open.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.qys.livesMall.open.modal.dto.app.H2AppOpenPushDTO;
import com.qys.livesMall.open.modal.entity.H2AppOpenPush;
import com.qys.livesMall.open.mapper.H2AppOpenPushMapper;
import com.qys.livesMall.open.modal.vo.H2AppOpenPushVo;
import com.qys.livesMall.open.service.H2AppOpenPushService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 
 * @since 2023-07-20
 */
@Service
public class H2H2AppOpenPushServiceImpl extends ServiceImpl<H2AppOpenPushMapper, H2AppOpenPush> implements H2AppOpenPushService {

    @Override
    public List<H2AppOpenPushVo> getinfo(Long userId) {
        LambdaQueryWrapper<H2AppOpenPush> queryWrapper=new LambdaQueryWrapper();
        queryWrapper.eq(H2AppOpenPush::getUserId,userId);
        queryWrapper.eq(H2AppOpenPush::getDeleted,0);
        List<H2AppOpenPush> list=list(queryWrapper);
        if (CollectionUtils.isNotEmpty(list)){
            List<H2AppOpenPushVo> pushVos= BeanUtil.copyToList(list,H2AppOpenPushVo.class);
            return pushVos;
        }else {
            return new ArrayList<>();
        }

    }

    @Override
    public boolean adds(List<H2AppOpenPushDTO> list) {
        if (CollectionUtils.isNotEmpty(list)){
            List<H2AppOpenPush> pushVos= BeanUtil.copyToList(list,H2AppOpenPush.class);
            return saveOrUpdateBatch(pushVos);
        }
        return false;
    }
}
